﻿/////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	ViewQ3
//  
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/01/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Globalization;
using System.Data.SQLite;

namespace Map_Fvg
{
    partial class ViewQ
    {

        public static int noFilesSelected;

        private int openUnione()
        {

            string path = FormIniz.quadroUnione5000;

            string[] fileEntries = Directory.GetFileSystemEntries(path, "*.txt");
            foreach (string fileName in fileEntries)
            {
                if (fileName.Contains("Quadro25000.jpg")) continue;

                File.Delete(fileName);
            }

            string path1 = FormIniz.cartellaElementi;
            string[] fileEntries1 = Directory.GetFileSystemEntries(path1, "*.zip");

            int iret = 0;
            for(int i = 0;i < UnioneDialog.noFiles; ++i)
            {
                string ss = UnioneDialog.fileUnione[i].Trim();
                if (ss == string.Empty) RestoreFile1(i);
                else
                {
                    foreach (string fileName in fileEntries1)
                    {
                        int ipos = fileName.LastIndexOf('\\');
                        ++ipos;
                        int len = fileName.Length;
                        string s1 = fileName.Substring(ipos, len - ipos);
                        ipos = s1.IndexOf(".", 0);
                        string s2 = s1.Substring(0, ipos);
                        if (s2.Equals(ss))
                        {
                            iret = FormIniz.RestoreFiles(fileName, i);
                            if (iret > 0)
                            {
                                MessageBox.Show("errore " + ss);
                                goto L20;
                            }
                        }
                    }
                }
            }

        L20:    if (iret != 0) return(iret);
            iret = readFileLine4(path);
            if (iret != 0) return(iret); 
            ViewQ.scalaXY = 1.0F;

            iret = readFileText4(path);
            if (iret != 0) return (iret); 

            iret = readFileArea4(path);
            if (iret != 0) return (iret);

            iret = readFilePoint4(path);
            if (iret != 0) return (iret); 

            aggiornaSimboli();
            scalaXY = 1.0F;

            return (0);
        }

 //       public static Point[] vertU = new Point[4];

        static public int readFileLine4(string path)
        {
            string FileName = path + "line_dbf0.txt";
            StreamReader sf = File.OpenText(FileName);

            string s = sf.ReadLine();
            if (!s.Contains("numero records:")) 
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            int ipos = s.IndexOf(':');
            ++ipos;
            int length = s.Length;
            string ss = s.Substring(ipos, length - ipos);
            int nrec0 = int.Parse(ss);

            FileName = path + "line_dbf1.txt";
            StreamReader sf1 = File.OpenText(FileName);
            s = sf1.ReadLine();
            if (!s.Contains("numero records:")) 
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;
            ss = s.Substring(ipos, length - ipos);
            int nrec1 = int.Parse(ss);

            FileName = path + "line_dbf2.txt";
            StreamReader sf2 = File.OpenText(FileName);
            s = sf2.ReadLine();
            if (!s.Contains("numero records:")) 
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;
            ss = s.Substring(ipos, length - ipos);
            int nrec2 = int.Parse(ss);

            FileName = path + "line_dbf3.txt";
            StreamReader sf3 = File.OpenText(FileName);
            s = sf3.ReadLine();
            if (!s.Contains("numero records:")) 
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;
            ss = s.Substring(ipos, length - ipos);
            int nrec3 = int.Parse(ss);


           int nrec = nrec0 + nrec1 + nrec2 + nrec3;

            max_nShapes = nrec + 100;   //      spazio per inserimento nuove linee

            vectShapes = new vShapesL[max_nShapes];

            char[] delimiterChars2 = { '#' };
            string[] words;
            int i, ii = 0, ipn = 0;
            
            StreamReader sx = sf; 
            for (i = 0; i < nrec; ++i)
            {
                if (i >= nrec0) sx = sf1;
                if (i >= nrec0 + nrec1) sx = sf2;
                if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                s = sx.ReadLine();
                words = s.Split(delimiterChars2);
                vectS[ipn].codice = words[1].Trim();
                vectS[ipn].denom = words[2].Trim();
                vectS[ipn].classe = words[3].Trim();
                vectS[ipn].elemento = words[4].Trim();
                if (i == 0)
                {
                    ++ipn;
                    goto L40;
                }
                for (ii = 0; ii < ipn; ++ii)
                {
                    int icomp = string.Compare(vectS[ii].codice, 0, vectS[ipn].codice, 0, 8);
                    if (icomp == 0 ) goto L40;
                }
                ++ipn;
            L40:
                if (i == 0)
                {
                    vectShapes[i].pntSimb = 0;
                }
                else
                {
                    vectShapes[i].pntSimb = ii;
                }
                if (words.Length > 7)
                {
                    vectShapes[i].lunghezza = words[6].Trim();
                    vectShapes[i].quota = words[7].Trim();
                }
                else
                {
                    vectShapes[i].lunghezza = "0.0";
                    vectShapes[i].quota = "0.0";
                }
            }
            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            nSimb = ipn;
        
            Point[] vertU = new Point[4];
            char[] delimiterChars1 = { ' ' };

            selectedElement = UnioneDialog.fileUnione[3];
            if (selectedElement != string.Empty)
            {
                readQU5000(selectedElement);
                words = coordVertices.Split(delimiterChars1);
                vertU[0].X = int.Parse(words[0]);
                vertU[0].Y = int.Parse(words[1]);
            }
            else
            {
                selectedElement = UnioneDialog.fileUnione[2];
                if (selectedElement != string.Empty)
                {
                    readQU5000(selectedElement);
                    words = coordVertices.Split(delimiterChars1);
                    vertU[0].X = int.Parse(words[0]);
                    vertU[0].Y = int.Parse(words[1]);
                }
                else
                {
                    selectedElement = UnioneDialog.fileUnione[0];
                    if (selectedElement != string.Empty)
                    {
                        readQU5000(selectedElement);
                        words = coordVertices.Split(delimiterChars1);
                        vertU[0].X = int.Parse(words[0]);
                        vertU[0].Y = int.Parse(words[1]);
                    }
                }
            }

            selectedElement = UnioneDialog.fileUnione[0];
            if (selectedElement != string.Empty)
            {
                readQU5000(selectedElement);
                words = coordVertices.Split(delimiterChars1);
                vertU[1].X = int.Parse(words[2]);
                vertU[1].Y = int.Parse(words[3]);
            }
            else
            {
                selectedElement = UnioneDialog.fileUnione[1];
                if (selectedElement != string.Empty)
                {
                    readQU5000(selectedElement);
                    words = coordVertices.Split(delimiterChars1);
                    vertU[1].X = int.Parse(words[2]);
                    vertU[1].Y = int.Parse(words[3]);
                }
                else
                {
                    selectedElement = UnioneDialog.fileUnione[3];
                    if (selectedElement != string.Empty)
                    {
                        readQU5000(selectedElement);
                        words = coordVertices.Split(delimiterChars1);
                        vertU[1].X = int.Parse(words[2]);
                        vertU[1].Y = int.Parse(words[3]);
                    }
                }
            }

            selectedElement = UnioneDialog.fileUnione[1];
            if (selectedElement != string.Empty)
            {
                readQU5000(selectedElement);
                words = coordVertices.Split(delimiterChars1);
                vertU[2].X = int.Parse(words[4]);
                vertU[2].Y = int.Parse(words[5]);
            }
            else
            {
                selectedElement = UnioneDialog.fileUnione[0];
                if (selectedElement != string.Empty)
                {
                    readQU5000(selectedElement);
                    words = coordVertices.Split(delimiterChars1);
                    vertU[2].X = int.Parse(words[4]);
                    vertU[2].Y = int.Parse(words[5]);
                }
                else
                {
                    selectedElement = UnioneDialog.fileUnione[2];
                    if (selectedElement != string.Empty)
                    {
                        readQU5000(selectedElement);
                        words = coordVertices.Split(delimiterChars1);
                        vertU[2].X = int.Parse(words[4]);
                        vertU[2].Y = int.Parse(words[5]);
                    }
                }
            }


            selectedElement = UnioneDialog.fileUnione[2];
            if (selectedElement != string.Empty)
            {
                readQU5000(selectedElement);
                words = coordVertices.Split(delimiterChars1);
                vertU[3].X = int.Parse(words[6]);
                vertU[3].Y = int.Parse(words[7]);
            }
            else
            {
                selectedElement = UnioneDialog.fileUnione[3];
                if (selectedElement != string.Empty)
                {
                    readQU5000(selectedElement);
                    words = coordVertices.Split(delimiterChars1);
                    vertU[3].X = int.Parse(words[6]);
                    vertU[3].Y = int.Parse(words[7]);
                }
                else
                {
                    selectedElement = UnioneDialog.fileUnione[1];
                    if (selectedElement != string.Empty)
                    {
                        readQU5000(selectedElement);
                        words = coordVertices.Split(delimiterChars1);
                        vertU[3].X = int.Parse(words[6]);
                        vertU[3].Y = int.Parse(words[7]);
                    }
                }
            }


   //       MessageBox.Show("***   " + UnioneDialog.fileUnione[3].ToString() + "  " + UnioneDialog.fileUnione[0].ToString() + "  " + UnioneDialog.fileUnione[1].ToString() + "  " + UnioneDialog.fileUnione[2].ToString());
   //       MessageBox.Show("***   " +vertU[0].ToString() + "  " + vertU[1].ToString() + "  " + vertU[2].ToString() + " " + vertU[3].ToString());     

            int XXmin = vertU[0].X;
            if (XXmin > vertU[1].X) XXmin = vertU[1].X;
           
            
            noFilesSelected = 0;
            for (int i4 = 0; i4 < 4; ++i4)
            {
                selectedElement = UnioneDialog.fileUnione[i4];
                if (selectedElement != string.Empty) ++noFilesSelected;
            }

            double Xdiff = vert[1].X - vert[0].X;
            double Ydiff = vert[1].Y - vert[0].Y;
            double alphaRad = Math.Atan2(Xdiff, Ydiff);

            alpha = -(float)(180.0 * alphaRad / Math.PI);

            if (noFilesSelected == 3)
            {
                if (vertU[2].X < vertU[3].X) vertU[2].X = vertU[3].X;
                if (vertU[0].X > vertU[1].X) vertU[0].X = vertU[1].X;
            }

            vert[0] = vertU[0];
            vert[1] = vertU[1];
            vert[2] = vertU[2];
            vert[3] = vertU[3];

 
            coordVertices = " " + vertU[0].X.ToString() + " " + vertU[0].Y.ToString() + " " + vertU[1].X.ToString() + " " + vertU[1].Y.ToString() +" " +
                vertU[2].X.ToString() + " " + vertU[2].Y.ToString() + " " + vertU[3].X.ToString() + " " + vertU[3].Y.ToString();

            computeRet();

            for (i = 0; i < nSimb; ++i)
            {
                vectS[i].penType = 1;
                vectS[i].penWidth = 1;
                vectS[i].icolor = Color.Black;
                vectS[i].visib = 1;
                vectS[i].tratto = "1 / 0.13";
                vectS[i].selected = 1;

            }
                 

            FileName = path + "\\line_shp0.txt";
            sf = File.OpenText(FileName);

            s = sf.ReadLine();
            if (!s.Contains("Shapefile type: ArcZ"))
            {
                MessageBox.Show("file line_shp.txt  non conforme");
                return 1;
            }
            char[] delimiterChars0 = { ':', ';' };

            words = s.Split(delimiterChars0);

            ss = words[2];
            int irec0 = int.Parse(ss);

            ss = words[4];
            int nPoints0 = int.Parse(ss);

                FileName = path + "\\line_shp1.txt";
                sf1 = File.OpenText(FileName);

                s = sf1.ReadLine();
                if (!s.Contains("Shapefile type: ArcZ"))
                {
                    MessageBox.Show("file line_shp1.txt  non conforme");
                    return 1;
                }
                char[] delimiterChars11 = { ':', ';' };

                words = s.Split(delimiterChars11);

                ss = words[2];
                //           MessageBox.Show("numero records: " + ss);
                int irec1 = int.Parse(ss);

                ss = words[4];
                //                    MessageBox.Show("numero punti: " + ss);
                int nPoints1 = int.Parse(ss);
            

                FileName = path + "\\line_shp2.txt";
                sf2 = File.OpenText(FileName);

                s = sf2.ReadLine();
                if (!s.Contains("Shapefile type: ArcZ"))
                {
                    MessageBox.Show("file line_shp.txt  non conforme");
                    return 1;
                }
                char[] delimiterChars21 = { ':', ';' };

                words = s.Split(delimiterChars21);

                ss = words[2];
                int irec2 = int.Parse(ss);

                ss = words[4];
               int  nPoints2 = int.Parse(ss);

                FileName = path + "\\line_shp3.txt";
                sf3 = File.OpenText(FileName);

                s = sf3.ReadLine();
                if (!s.Contains("Shapefile type: ArcZ"))
                {
                    MessageBox.Show("file line_shp.txt  non conforme");
                    return 1;
                }
                      char[] delimiterChars3 = { ':', ';' };

                words = s.Split(delimiterChars3);

                ss = words[2];
                //           MessageBox.Show("numero records: " + ss);
                int irec3 = int.Parse(ss);

                ss = words[4];
                //                    MessageBox.Show("numero punti: " + ss);
                int nPoints3 = int.Parse(ss);

            
            int nPoints = nPoints0 + nPoints1 + nPoints2 + nPoints3;
            int irec = irec0 + irec1 + irec2 + irec3;


            if (nrec != irec) {
                MessageBox.Show("files shp non congruente con dbf: " + nrec.ToString() + "/  " + irec.ToString());
                return 1;
            }

            int max_nPoints = nPoints + 5000;   //  spazio per inserimento nuovi punti

            nShapes = irec;

            PL = new Point[max_nPoints];

            s = sf.ReadLine();

            char[] delimiterChars = { ':', ',' };

            words = s.Split(delimiterChars);

            Xmin = int.Parse(words[1]);
            Ymin = int.Parse(words[2]);
            Xmax = int.Parse(words[3]);
            Ymax = int.Parse(words[4]);

            int idShape, nParts;
            int nVertices, ipnt;
            ipnt = 0;
            int XX, YY;
            int iShapes = 0;
            char[] delimiterChars20 = { ':', ',', '=' };

            s = sf1.ReadLine();
            s = sf2.ReadLine();
            s = sf3.ReadLine();

            sx = sf; 
            for (i = 0; i < nShapes; ++i)
            {
                if (i >= irec0) sx = sf1;
                if (i >= irec0+irec1) sx = sf2;
                if (i >= irec0 + irec1+irec2) sx = sf3;

                s = sx.ReadLine();

                words = s.Split(delimiterChars20);

                ss = words[1];
                idShape = int.Parse(ss);

                ss = words[3];
                nVertices = int.Parse(ss);

                ss = words[5];
                nParts = int.Parse(ss);

                vectShapes[i].nVertices = nVertices;
                vectShapes[i].pntpL = ipnt;

                s = sx.ReadLine();

                words = s.Split(delimiterChars20);

                vectShapes[i].PointA.X = int.Parse(words[1]);
                vectShapes[i].PointA.Y = int.Parse(words[2]);
                vectShapes[i].PointB.X = int.Parse(words[3]);
                vectShapes[i].PointB.Y = int.Parse(words[4]);
                vectShapes[i].selected = 0;

                if (nParts != 1)
                {
                    s = sx.ReadLine();
                }

                int pntSimb = vectShapes[i].pntSimb;
                if (vectS[pntSimb].selected == 1 )
                {
                    if (iShapes == 0)
                    {
                        Xmin = vectShapes[i].PointA.X;
                        Ymin = vectShapes[i].PointA.Y;
                        Xmax = vectShapes[i].PointB.X;
                        Ymax = vectShapes[i].PointB.Y;
                        iShapes = 1;
                    }
                    else
                    {
                        if (vectShapes[i].PointA.X < Xmin)
                            Xmin = vectShapes[i].PointA.X;
                        if (vectShapes[i].PointA.Y < Ymin)
                            Ymin = vectShapes[i].PointA.Y;
                        if (vectShapes[i].PointB.X > Xmax)
                            Xmax = vectShapes[i].PointB.X;
                        if (vectShapes[i].PointB.Y > Ymax)
                            Ymax = vectShapes[i].PointB.Y;
                    }
                    ++iShapes;
                }

                for (int j = 0; j < nVertices; ++j)
                {
                    s = sx.ReadLine();

                    words = s.Split(delimiterChars20);

                    XX = int.Parse(words[0]);

                    YY = int.Parse(words[1]);

                    PL[ipnt].X = XX;
                    PL[ipnt].Y = YY;
                    ++ipnt;
                }

            }
            readViewQ = 1;

            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            return 0;
        }

        private void openUnione1()
        {

            noFilesSelected = 0;
            for (int i4 = 0; i4 < 4; ++i4)
            {
                selectedElement = UnioneDialog.fileUnione[i4];
                if (selectedElement != string.Empty) ++noFilesSelected;
            }
        }

        static public int readFileText4(string path)
        {
            string FileName = path + "\\text_dbf0.txt";
            StreamReader sf = File.OpenText(FileName);
            string s = "";
            s = sf.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            int ipos = s.IndexOf(':');
            ++ipos;
            int length = s.Length;

            string ss = s.Substring(ipos, length - ipos);

            int nrec0 = int.Parse(ss);



            FileName = path + "\\text_dbf1.txt";
            StreamReader sf1 = File.OpenText(FileName);
            s = sf1.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);

            int nrec1 = int.Parse(ss);



            FileName = path + "\\text_dbf2.txt";
            StreamReader sf2 = File.OpenText(FileName);
            s = sf2.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);

            int nrec2 = int.Parse(ss);



            FileName = path + "\\text_dbf3.txt";
            StreamReader sf3 = File.OpenText(FileName);
            s = sf3.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);

            int nrec3 = int.Parse(ss);

            int nrec = nrec0 + nrec1 + nrec2 + nrec3;

            nShapesT = nrec;
            max_nShapesT = nrec + 100;
            vectShapesT = new vShapesT[max_nShapesT];

            int i, ii = 0, ipn = 0;

            char[] delimiterChars2 = { '#' };
            string[] words;
            NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;

             StreamReader sx = sf; 
            for (i = 0; i < nrec; ++i)
            {
                if (i >= nrec0) sx = sf1;
                if (i >= nrec0 + nrec1) sx = sf2;
                if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                s = sx.ReadLine();
                words = s.Split(delimiterChars2);

                vectT[ipn].codice = words[1].Trim();
                vectT[ipn].denom = words[2].Trim();
                vectT[ipn].classe = words[3].Trim();
                vectT[ipn].elemento = words[4].Trim();
                ss = words[5].Trim();
                vectT[ipn].edizione = int.Parse(ss);
                ss = words[7].Trim();
                vectT[ipn].altezza = float.Parse(ss, nfi);

                if (i == 0)
                {
                    ++ipn;
                    goto L40;
                }
                for (ii = 0; ii < ipn; ++ii)
                {
                    int icomp = string.Compare(vectT[ii].codice, 0, vectT[ipn].codice, 0, 8);
                    if (icomp == 0 ) goto L40;
                }
                ++ipn;
            L40:
                if (i == 0)
                {
                    vectShapesT[i].pntSimb = 0;
                }
                else
                {
                    vectShapesT[i].pntSimb = ii;
                }

                vectShapesT[i].selected = 1;

                vectShapesT[i].testo = words[6].Trim();

                ss = words[7].Trim();

                vectShapesT[i].altezza = float.Parse(ss, nfi);

                ss = words[9].Trim();
                int ncar = int.Parse(ss);

                ss = words[8].Trim();
                vectShapesT[i].rotazione = float.Parse(ss, nfi);
                ss = words[9].Trim();
                vectShapesT[i].ncar_testo = int.Parse(ss);
                ss = words[10].Trim();
                vectShapesT[i].cod_posiz = int.Parse(ss);
                ss = words[11].Trim();
                vectShapesT[i].GMrotation = float.Parse(ss, nfi);

                vectShapesT[i].modifica = 0;
            }

            nSimbT = ipn;
            ipn = 0;
            for (i = 0; i < nSimbT; ++i)
            {
                vectT[i].penType = 1;
                vectT[i].penWidth = 1;
                vectT[i].icolor = Color.Black;
                vectT[i].iFont = new Font("Microsoft Sans Serif", 6.0F, FontStyle.Regular, GraphicsUnit.Point);
                vectT[i].visib = 1;
            }
                sf.Close();
                sf1.Close();
                sf2.Close();
                sf3.Close();

            FileName = path + "\\text_shp0.txt";
            sf = File.OpenText(FileName);

            s = sf.ReadLine();
            if (!s.Contains("Shapefile type: MultiPointZ"))
            {
                MessageBox.Show("file text_shp.txt  non conforme");
                return 1;
            }
            char[] delimiterChars0 = { ':', ';' };
            words = s.Split(delimiterChars0);

            ss = words[2];
            int irec0 = int.Parse(ss);

            if (nrec0 != irec0)
            {
                MessageBox.Show("file shp non congruente con dbf: " + nrec.ToString() + "/  " + nrec1.ToString());
                return 1;

            }
            s = sf.ReadLine();

            FileName = path + "\\text_shp1.txt";
            sf1 = File.OpenText(FileName);

            s = sf1.ReadLine();
            if (!s.Contains("Shapefile type: MultiPointZ"))
            {
                MessageBox.Show("file text_shp1.txt  non conforme");
                return 1;
            }
            words = s.Split(delimiterChars0);

            ss = words[2];
            int irec1 = int.Parse(ss);


            if (nrec1 != irec1)
            {
                MessageBox.Show("file shp1 non congruente con dbf: " + nrec.ToString() + "/  " + nrec1.ToString());
                return 1;

            }
            s = sf1.ReadLine();

            FileName = path + "\\text_shp2.txt";
            sf2 = File.OpenText(FileName);

            s = sf2.ReadLine();
            if (!s.Contains("Shapefile type: MultiPointZ"))
            {
                MessageBox.Show("file text_shp2.txt  non conforme");
                return 1;
            }
            words = s.Split(delimiterChars0);

            ss = words[2];
            //           MessageBox.Show("numero records: " + ss);
            int irec2 = int.Parse(ss);


            if (nrec2 != irec2)
            {
                MessageBox.Show("file shp2 non congruente con dbf: " + nrec.ToString() + "/  " + nrec1.ToString());
                return 1;

            }
            s = sf2.ReadLine();

            FileName = path + "\\text_shp3.txt";
            sf3 = File.OpenText(FileName);
            s = sf3.ReadLine();
            if (!s.Contains("Shapefile type: MultiPointZ"))
            {
                MessageBox.Show("file text_shp3.txt  non conforme");
                return 1;
            }
            words = s.Split(delimiterChars0);

            ss = words[2];
            int irec3 = int.Parse(ss);


            if (nrec3 != irec3)
            {
                MessageBox.Show("file shp non congruente con dbf: " + nrec.ToString() + "/  " + nrec1.ToString());
                return 1;

            }
            s = sf3.ReadLine();

     
            int idShape, nParts;
            int nVertices, ipnt;
            ipnt = 0;
            int XX, YY;
            char[] delimiterChars3 = { ':', ',', '=' };

            sx = sf; 
            for (i = 0; i < nShapesT; ++i)
            {
                if (i >= irec0) sx = sf1;
                if (i >= irec0+irec1) sx = sf2;
                if (i >= irec0 + irec1+irec2) sx = sf3;

                s = sx.ReadLine();


                words = s.Split(delimiterChars3);

                ss = words[1];
                idShape = int.Parse(ss);

                ss = words[3];
                nVertices = int.Parse(ss);

                ss = words[5];
                nParts = int.Parse(ss);
 
                s = sx.ReadLine();

                for (int j = 0; j < nVertices; ++j)
                {
                    s = sx.ReadLine();

                    words = s.Split(delimiterChars3);

                    XX = int.Parse(words[0]);

                    YY = int.Parse(words[1]);

                    vectShapesT[ipnt].XX.X = XX;
                    vectShapesT[ipnt].XX.Y = YY;
                    vectShapesT[ipnt].modifica = 0;
                    ++ipnt;
                }

            }

            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();


            return 0;
        }

        static public int readFilePoint4(string path)
        {
            string FileName = path + "\\point_dbf0.txt";
            StreamReader sf = File.OpenText(FileName);
            string s = sf.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + path + " non conforme");
                return 1;
            }
            int ipos = s.IndexOf(':');
            ++ipos;
            int length = s.Length;

            string ss = s.Substring(ipos, length - ipos);
            int nrec0 = int.Parse(ss);

            FileName = path + "\\point_dbf1.txt";
            StreamReader sf1 = File.OpenText(FileName);
            s = sf1.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec1 = int.Parse(ss);

            FileName = path + "\\point_dbf2.txt";
            StreamReader sf2 = File.OpenText(FileName);
            s = sf2.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec2 = int.Parse(ss);


            FileName = path + "\\point_dbf3.txt";
            StreamReader sf3 = File.OpenText(FileName);
            s = sf3.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec3 = int.Parse(ss);

            int nrec = nrec0 + nrec1 + nrec2 + nrec3;

            vectShapesP = new vShapesP[nrec];

            int i, ii = 0, ipn = 0;

            char[] delimiterChars = { '#' };
            NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;

            StreamReader sx = sf; 
            for (i = 0; i < nrec; ++i)
            {
                if (i >= nrec0) sx = sf1;
                if (i >= nrec0 + nrec1) sx = sf2;
                if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                s = sx.ReadLine();
                string[] words = s.Split(delimiterChars);

                ss = words[1].Trim();
                vectP[ipn].codice = ss;
                ss = words[2].Trim();
                vectP[ipn].denom = ss;
                ss = words[3].Trim();
                vectP[ipn].classe = ss;
                ss = words[4].Trim();
                vectP[ipn].elemento = ss;
                ss = words[8].Trim();
                vectP[ipn].dimensione = float.Parse(ss, nfi);
                if (i == 0)
                {
                    ++ipn;
                    goto L40;
                }
                for (ii = 0; ii < ipn; ++ii)
                {
                    int icomp = string.Compare(vectP[ii].codice, 0, vectP[ipn].codice, 0, 8);
                    if (icomp == 0 ) goto L40;
                }
                ++ipn;
            L40:
                if (i == 0)
                {
                    vectShapesP[i].pntSimb = 0;
                }
                else
                {
                    vectShapesP[i].pntSimb = ii;
                }

                ss = words[5].Trim();
                vectShapesP[i].edizione = int.Parse(ss, nfi);

                ss = words[6].Trim();
                vectShapesP[i].quota = float.Parse(ss, nfi);

                ss = words[7].Trim();
                vectShapesP[i].rotazione = float.Parse(ss, nfi);

                ss = words[9].Trim();
                vectShapesP[i].GMrotation = float.Parse(ss, nfi);
            }
            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            nSimbP = ipn;
            ipn = 0;

            for (i = 0; i < nSimbP; ++i)
            {
                vectP[i].icolor = Color.Black;
                vectP[i].iFont = new Font("Microsoft Sans Serif", 5.0F, FontStyle.Regular, GraphicsUnit.Point);
                vectP[i].visib = 0;
                vectP[i].simbolo = 1;
                vectP[i].paramSimb = " ";
                vectP[i].selected = 1;
            }

            {
                FileName = path + "\\point_shp0.txt";
                sf = File.OpenText(FileName);

                s = sf.ReadLine();
                if (!s.Contains("Shapefile type: MultiPointZ"))
                {
                    MessageBox.Show("file point_shp.txt  non conforme");
                    return 1;
                }
                char[] delimiterChars0 = { ':', ';' };
                string[] words = s.Split(delimiterChars0);

                ss = words[2];
                int irec0 = int.Parse(ss);

                FileName = path + "\\point_shp1.txt";
                sf1 = File.OpenText(FileName);

                s = sf1.ReadLine();
                if (!s.Contains("Shapefile type: MultiPointZ"))
                {
                    MessageBox.Show("file point_shp.txt  non conforme");
                    return 1;
                }
                words = s.Split(delimiterChars0);

                ss = words[2];
                //           MessageBox.Show("numero records: " + ss);
                int irec1 = int.Parse(ss);


                FileName = path + "\\point_shp2.txt";
                sf2 = File.OpenText(FileName);

                s = sf2.ReadLine();
                if (!s.Contains("Shapefile type: MultiPointZ"))
                {
                    MessageBox.Show("file point_shp.txt  non conforme");
                    return 1;
                }
        //        char[] delimiterChars0 = { ':', ';' };
                words = s.Split(delimiterChars0);

                ss = words[2];
                int irec2 = int.Parse(ss);

                FileName = path + "\\point_shp3.txt";
                sf3 = File.OpenText(FileName);

                s = sf3.ReadLine();
                if (!s.Contains("Shapefile type: MultiPointZ"))
                {
                    MessageBox.Show("file point_shp.txt  non conforme");
                    return 1;
                }
                words = s.Split(delimiterChars0);

                ss = words[2];
                int irec3 = int.Parse(ss);


                int irec = irec0 + irec1 + irec2 + irec3;
                if (nrec != irec)
                {
                    MessageBox.Show("file shp non congruente con dbf: " + nrec.ToString() + "/  " + irec.ToString());
                    return 1;

                }

                nShapesP = nrec;

                s = sf.ReadLine();
                s = sf1.ReadLine();
                s = sf2.ReadLine();
                s = sf3.ReadLine();

                int idShape, nParts;
                int nVertices, ipnt;
                ipnt = 0;
                int XX, YY;



               char[] delimiterChars2 = { ':', ',', '=' };
            sx = sf; 
            for (i = 0; i < nShapesP; ++i)
            {
                if (i >= nrec0) sx = sf1;
                if (i >= nrec0 + nrec1) sx = sf2;
                if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                s = sx.ReadLine();

                    words = s.Split(delimiterChars2);

                    ss = words[1];
                    idShape = int.Parse(ss);

                    ss = words[3];
                    nVertices = int.Parse(ss);

                    ss = words[5];
                    nParts = int.Parse(ss);
                    s = sx.ReadLine();

                    for (int j = 0; j < nVertices; ++j)
                    {
                        s = sx.ReadLine();

                        words = s.Split(delimiterChars2);

                        XX = int.Parse(words[0]);

                        YY = int.Parse(words[1]);

                        vectShapesP[ipnt].XX.X = XX;
                        vectShapesP[ipnt].XX.Y = YY;
                        ++ipnt;
                    }

                }
            }
            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            return 0;
        }

        static public int readFileArea4(string path)
        {
            string FileName = path + "\\area_dbf0.txt";
            StreamReader sf = File.OpenText(FileName);
            string s = sf.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            int ipos = s.IndexOf(':');
            ++ipos;
            int length = s.Length;

            string ss = s.Substring(ipos, length - ipos);
            int nrec0 = int.Parse(ss);

            FileName = path + "\\area_dbf1.txt";
            StreamReader sf1 = File.OpenText(FileName);
            s = sf1.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName+ " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec1 = int.Parse(ss);

            FileName = path + "\\area_dbf2.txt";
            StreamReader sf2 = File.OpenText(FileName);
            s = sf2.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec2 = int.Parse(ss);

            FileName = path + "\\area_dbf3.txt";
            StreamReader sf3 = File.OpenText(FileName);
            s = sf3.ReadLine();
            if (!s.Contains("numero records:"))
            {
                MessageBox.Show("file " + FileName + " non conforme");
                return 1;
            }
            ipos = s.IndexOf(':');
            ++ipos;
            length = s.Length;

            ss = s.Substring(ipos, length - ipos);
            int nrec3 = int.Parse(ss);

            int nrec = nrec0 + nrec1 + nrec2 + nrec3; 

             vectShapesA = new vShapesA[nrec];

            int i, ii = 0, ipn = 0;

            char[] delimiterChars = { '#' };

            StreamReader sx = sf; 
            for (i = 0; i < nrec; ++i)
            {
                if (i >= nrec0) sx = sf1;
                if (i >= nrec0 + nrec1) sx = sf2;
                if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                s = sx.ReadLine();
                string[] words = s.Split(delimiterChars);

                ss = words[1].Trim();
                vectA[ipn].codice = ss;
                ss = words[2].Trim();
                vectA[ipn].denom = ss;
                ss = words[3].Trim();
                vectA[ipn].classe = ss;
                ss = words[4].Trim();
                vectA[ipn].elemento = ss;
                vectShapesA[i].elemento = ss;
                if (i == 0)
                {
                    ++ipn;
                    goto L40;
                }
                for (ii = 0; ii < ipn; ++ii)
                {
                    int icomp = string.Compare(vectA[ii].codice, 0, vectA[ipn].codice, 0, 8);
                    if (icomp == 0 ) goto L40;
                }
                ++ipn;
            L40:
                if (i == 0)
                {
                    vectShapesA[i].pntSimb = 0;
                }
                else
                {
                    vectShapesA[i].pntSimb = ii;
                }
            }

            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            nSimbA = ipn;

            ipn = 0;
            for (i = 0; i < nSimbA; ++i)
            {
                vectA[i].penType = 1;
                vectA[i].penWidth = 1;
                vectA[i].icolor = Color.Black;
                vectA[i].iFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
                vectA[i].visib = 1;
                vectA[i].codice_bordo = 1;
                vectA[i].bordo = " 1 / 0.13";
                vectA[i].codice_camp = 0;
                vectA[i].campitura = " ";
                vectA[i].selected = 1;
            }

            {
                FileName = path + "\\area_shp0.txt";
                sf = File.OpenText(FileName);

                s = sf.ReadLine();
                if (!s.Contains("Shapefile type: PolygonZ"))
                {
                    MessageBox.Show("file area_shp.txt  non conforme");
                    return 1;
                }
                char[] delimiterChars0 = { ':', ';' };
                string[] words = s.Split(delimiterChars0);

                ss = words[2];
                //           MessageBox.Show("numero records: " + ss);
                int irec0 = int.Parse(ss);
                ss = words[4];
                //           MessageBox.Show("numero punti: " + ss);
                int nPoints0 = int.Parse(ss);


                FileName = path + "\\area_shp1.txt";
                sf1 = File.OpenText(FileName);

                s = sf1.ReadLine();
                if (!s.Contains("Shapefile type: PolygonZ"))
                {
                    MessageBox.Show("file area_shp1.txt  non conforme");
                    return 1;
                }
                words = s.Split(delimiterChars0);

                ss = words[2];
                int irec1 = int.Parse(ss);
                ss = words[4];
                int nPoints1 = int.Parse(ss);

                FileName = path + "\\area_shp2.txt";
                sf2 = File.OpenText(FileName);

                s = sf2.ReadLine();
                if (!s.Contains("Shapefile type: PolygonZ"))
                {
                    MessageBox.Show("file area_shp2.txt  non conforme");
                    return 1;
                }
                words = s.Split(delimiterChars0);

                ss = words[2];
                int irec2 = int.Parse(ss);
                ss = words[4];
                int nPoints2 = int.Parse(ss);

                FileName = path + "\\area_shp3.txt";
                sf3 = File.OpenText(FileName);

                s = sf3.ReadLine();
                if (!s.Contains("Shapefile type: PolygonZ"))
                {
                    MessageBox.Show("file area_shp.txt  non conforme");
                    return 1;
                }
                words = s.Split(delimiterChars0);

                ss = words[2];
                int irec3 = int.Parse(ss);
                ss = words[4];
                int nPoints3 = int.Parse(ss);


                int irec = irec0 + irec1 + irec2 + irec3;
                nPointsA = nPoints0 + nPoints1 + nPoints2 + nPoints3;
                nShapesA = irec;
                if (nrec != irec)
                {
                    MessageBox.Show("file area_shp non congruente con dbf: " + nrec1.ToString() + "/  " + nrec1.ToString());
                    return 1;

                }
                PA = new Point[nPointsA];

                s = sf.ReadLine();

                char[] delimiterChars1 = { ':', ',' };

                words = s.Split(delimiterChars1);

                s = sf1.ReadLine();
                s = sf2.ReadLine();
                s = sf3.ReadLine();

                int idShape, nParts;
                int nVertices, ipnt;
                ipnt = 0;
                int XX, YY;

                char[] delimiterChars2 = { ':', ',', '=' };
                sx = sf;
                for (i = 0; i < nrec; ++i)
                {
                    if (i >= nrec0) sx = sf1;
                    if (i >= nrec0 + nrec1) sx = sf2;
                    if (i >= nrec0 + nrec1 + nrec2) sx = sf3;

                    s = sx.ReadLine();

                   words = s.Split(delimiterChars2);

                    ss = words[1];
                    idShape = int.Parse(ss);

                    ss = words[3];
                    nVertices = int.Parse(ss);

                    ss = words[5];
                    nParts = int.Parse(ss);

                    vectShapesA[i].nVertices = nVertices;
                    vectShapesA[i].pntPA = ipnt;

                    s = sx.ReadLine();

                    words = s.Split(delimiterChars2);

                    vectShapesA[i].PointA.X = int.Parse(words[1]);
                    vectShapesA[i].PointA.Y = int.Parse(words[2]);
                    vectShapesA[i].PointB.X = int.Parse(words[3]);
                    vectShapesA[i].PointB.Y = int.Parse(words[4]);

                    int pntSimb = vectShapesA[i].pntSimb;

                    if (nParts != 1)
                    {
                        s = sx.ReadLine();
                        int ipos1 = s.IndexOf(":", 0);
                        ++ipos1;
                        int len = s.Length;
                        vectShapesA[i].nParts = nParts;
                        vectShapesA[i].Parts_string = s.Substring(ipos1, len - ipos1);
 //                       string xx = s.Substring(ipos1, len - ipos1);
                        //                       MessageBox.Show("read:  " + i.ToString() + "  " + xx);
                    }
                    else
                    {
                        vectShapesA[i].nParts = 1;
                        vectShapesA[i].Parts_string = string.Empty;
                    }
                    for (int j = 0; j < nVertices; ++j)
                    {
                        s = sx.ReadLine();
                        ss = s.Substring(4, s.Length - 4);
                        words = ss.Split(delimiterChars2);

                        XX = int.Parse(words[0]);

                        YY = int.Parse(words[1]);

                        PA[ipnt].X = XX;
                        PA[ipnt].Y = YY;
                        ++ipnt;
                    }

                }
            }
            sf.Close();
            sf1.Close();
            sf2.Close();
            sf3.Close();

            return 0;
        }

        private static void RestoreFile1(int ipt)
        {
            string path = FormIniz.quadroUnione5000;

            string path1 = string.Concat(path, "line_dbf", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "numero records:     0";
                sw.WriteLine(info);
            }

            path1 = string.Concat(path,"line_shp",ipt.ToString(),".txt");
            using(StreamWriter sw = File.CreateText(path1))
            {
                string info = "Shapefile type: ArcZ  # of Shape:     0; # of Points: 0";
                string info1 = "File Bounds:       0,        0,        0,        0";
                sw.WriteLine(info);
                sw.WriteLine(info1);
            }

            path1 = string.Concat(path, "area_dbf", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "numero records:      0";
                sw.WriteLine(info);
            }

            path1 = string.Concat(path, "area_shp", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "Shapefile type: PolygonZ  # of Shape:   0; # of Points:    0";
                string info1 = "File Bounds:       0,        0,        0,        0";
                sw.WriteLine(info);
                sw.WriteLine(info1);
            }

            path1 = string.Concat(path, "text_dbf", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "numero records:      0";
                sw.WriteLine(info);
            }

            path1 = string.Concat(path, "text_shp", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "SShapefile type: MultiPointZ  # of Shape:    0; # of Points: 0";
                string info1 = "File Bounds:       0,        0,        0,        0";
                sw.WriteLine(info);
                sw.WriteLine(info1);
            }

            path1 = string.Concat(path, "point_dbf", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "numero records:      0";
                sw.WriteLine(info);
            }

            path1 = string.Concat(path, "point_shp", ipt.ToString(), ".txt");
            using (StreamWriter sw = File.CreateText(path1))
            {
                string info = "SShapefile type: MultiPointZ  # of Shape:     0; # of Points: 0";
                string info1 = "File Bounds:       0,        0,        0,        0";
                sw.WriteLine(info);
                sw.WriteLine(info1);
            }
        }

        private void aggiornaSimboli()
        {
            for (int i = 0; i < ViewQ.nSimb; ++i)
            {
                if (ViewQ.vectS[i].selected == 0) continue;
                string ss = ViewQ.vectS[i].codice.ToString();

                using (SQLiteConnection conn = SetConnection())
                {
                    conn.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn))
                    {
                        cmd.CommandText = "select * from linea where codice_stclasse = '" + ss + "'";

                        SQLiteDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                ViewQ.vectS[i].penType = int.Parse(reader.GetString(3).ToString());
                                ViewQ.vectS[i].tratto = reader.GetString(4).ToString();

                                string[] words;
                                char[] delimiterChars = { ' ', ',' };

                                string s1 = reader.GetString(5).ToString();
                                words = s1.Split(delimiterChars);
                                byte b1 = byte.Parse(words[0]);
                                byte b2 = byte.Parse(words[1]);
                                byte b3 = byte.Parse(words[2]);
                                byte b4 = byte.Parse(words[3]);
                                ViewQ.vectS[i].icolor = Color.FromArgb(b1, b2, b3, b4);
                            }
                        }
                    }
                    conn.Close();
                }

            }

            for (int i = 0; i < ViewQ.nSimbT; ++i)
            {
                if (ViewQ.vectT[i].selected == 0) continue;
                string ss = ViewQ.vectT[i].codice.ToString();

                using (SQLiteConnection conn = SetConnection())
                {
                    conn.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn))
                    {
                        cmd.CommandText = "select * from testo where codice_testo = '" + ss + "'";

                        SQLiteDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                string s1 = reader.GetString(2).ToString();
                                ViewQ.vectT[i].iFont = stringToFont(s1);

                                ViewQ.vectT[i].altezza = float.Parse(reader.GetString(4).ToString());

                                string[] words;
                                char[] delimiterChars = { ' ', ',' };

                                s1 = reader.GetString(3).ToString();
                                words = s1.Split(delimiterChars);
                                byte b1 = byte.Parse(words[0]);
                                byte b2 = byte.Parse(words[1]);
                                byte b3 = byte.Parse(words[2]);
                                byte b4 = byte.Parse(words[3]);
                                ViewQ.vectT[i].icolor = Color.FromArgb(b1, b2, b3, b4);
                            }
                        }
                        conn.Close();
                    }
                }
            }


            for (int i = 0; i < ViewQ.nSimbA; ++i)
            {
                if (ViewQ.vectA[i].selected == 0) continue;
                string ss = ViewQ.vectA[i].codice.ToString();

                using (SQLiteConnection conn = SetConnection())
                {
                    conn.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(conn))
                    {
                        cmd.CommandText = "select * from area where codice_area = '" + ss + "'";

                        SQLiteDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                string s1 = reader.GetString(2).ToString();
                                ViewQ.vectA[i].codice_bordo = int.Parse(reader.GetString(4).ToString());
                                ViewQ.vectA[i].bordo = reader.GetString(5).ToString();
                                ViewQ.vectA[i].codice_camp = int.Parse(reader.GetString(2).ToString());
                                ViewQ.vectA[i].campitura = reader.GetString(3).ToString();


                                s1 = reader.GetString(6).ToString();
                                string[] words;
                                char[] delimiterChars = { ' ', ',' };

                                words = s1.Split(delimiterChars);
                                byte b1 = byte.Parse(words[0]);
                                byte b2 = byte.Parse(words[1]);
                                byte b3 = byte.Parse(words[2]);
                                byte b4 = byte.Parse(words[3]);
                                ViewQ.vectA[i].icolor = Color.FromArgb(b1, b2, b3, b4);
                            }
                        }
                        conn.Close();
                    }
                }


            }
        }


        private SQLiteConnection SetConnection()
        {
            string DataSource = "Data Source=";
            DataSource = string.Concat(DataSource, FormIniz.cartellaSimb, ";");
            SQLiteConnection conn = new SQLiteConnection(DataSource);
            return (conn);
        }

        private Font stringToFont(string ss)
        {
            float sizef = 1.0F;
            int ipos = ss.IndexOf("Size=", 0);
            if (ipos > 0)
            {
                int ipos1 = ss.IndexOf(",", ipos);
                int len = ipos1 - ipos - 5;
                string s1 = ss.Substring(ipos + 5, len);
                sizef = float.Parse(s1);
            }

            Font ifont = new Font(ss, sizef);
            return (ifont);


        }
    }
}
